﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class FormAllLineLength : System.Windows.Forms.Form
	{
		public FormAllLineLength()
		{
			this.InitializeComponent();
			YJKProcessTools hyprocessTools = new YJKProcessTools();
			hyprocessTools.ShowInTaskbarChange(this);
			//base.Icon = Resource.YArchitechIcon;
			base.Location = new System.Drawing.Point(100, 100);
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		private void FormAllLineLength_MouseLeave(object sender, EventArgs e)
		{
			if (!base.ClientRectangle.Contains(Cursor.Position))
			{
				int wMsg = 7;
				FormAllLineLength.SendMessage(DrawLineAndWriteLength.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
				return;
			}
			base.Focus();
		}

		private void FormAllLineLength_FormClosed(object sender, FormClosedEventArgs e)
		{
			byte bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			int wMsg = 7;
			FormAllLineLength.SendMessage(DrawLineAndWriteLength.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			FormAllLineLength.keybd_event(bVk, 0, dwFlags, 0);
			FormAllLineLength.keybd_event(bVk, 0, dwFlags2, 0);
		}

		private void FormAllLineLength_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void FormAllLineLength_FormClosing(object sender, FormClosingEventArgs e)
		{
		}

		private void FormAllLineLength_Leave(object sender, EventArgs e)
		{
			if (!base.ClientRectangle.Contains(Cursor.Position))
			{
				int wMsg = 7;
				FormAllLineLength.SendMessage(DrawLineAndWriteLength.hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
				return;
			}
			base.Focus();
		}
	}
}
